<script setup>
import { ref } from 'vue'
import { Search } from '@element-plus/icons-vue'
const searchVal = ref('')
const activeTag = ref('')
const hotSearchList = ref(['AI助手', '公文写作', '虚拟女友', '创意灵感', '代码生成'])

const handleSearch = () => {
  if (!searchVal.value.trim()) return
  console.log('搜索内容：', searchVal.value)
}

const handleTagClick = (val) => {
  searchVal.value = val
  activeTag.value = val
  handleSearch()
}

const handleClear = () => {
  searchVal.value = ''
  activeTag.value = ''
}
</script>
<template>
  <el-row :gutter="20" class="row">
    <el-col :xs="24" :sm="8" :offset="0" class="left">
      <div class="search-wrapper">
        <div class="search-box-container">
          <el-input
            v-model="searchVal"
            placeholder="请搜索内容..."
            class="search-input"
            clearable
            @clear="handleClear"
            @keyup.enter="handleSearch"
          >
            <template #prefix>
              <el-icon class="search-icon"><Search /></el-icon>
            </template>
            <template #suffix>
              <el-button 
                type="primary" 
                size="small" 
                class="search-btn"
                @click="handleSearch"
              >
                搜索
              </el-button>
            </template>
          </el-input>
        </div>

        <div class="hot-search-container" v-if="hotSearchList.length">
          <span class="hot-label">热门搜索：</span>
          <div class="tags-wrap">
            <el-tag
              v-for="(item, idx) in hotSearchList"
              :key="idx"
              class="hot-tag"
              @click="handleTagClick(item)"
              :effect="item === activeTag ? 'solid' : 'plain'"
            >
              {{ item }}
            </el-tag>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="16" :offset="0" class="right">
      <div style="width: 100%;">
        <img src="@/assets/images/homeright.png" alt="" style="height: 140px; width: 100%; border-radius: 10px;">
      </div>
    </el-col>
  </el-row>
</template>
<style scoped>
.row {
  display: flex;
  align-items: center;
}
.search-wrapper {
  width: 100%;
  margin: 0;
  padding: 0 10px;
}

.search-box-container {
  width: 100%;
}

.search-input {
  height: 40px;
  border-radius: 20px;
  border: 1px solid #e5e7eb;
}

.search-icon {
  color: #9ca3af;
  margin-right: 8px;
}

.search-btn {
  height: 30px;
  padding: 0 14px;
  border-radius: 15px;
  margin-right: 4px;
  background-color: #409eff;
  border: none;
  font-size: 12px;
}

.hot-search-container {
  margin-top: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.hot-label {
  font-size: 13px;
  color: #6b7280;
  margin-right: 8px;
}

.tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hot-tag {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 15px;
  cursor: pointer;
}
.right img {
  border-radius: 10px;
}
</style>